package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.IntegralDeployMapper;
import com.tzbank.back.service.IntegralDeployService;
import com.tzbank.entity.backstage.IntegralDeploy;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

/**
 * 积分管理配置
 * @author 蔡宇钿
 *2018年6月4日
 */

@Service(value="IntegralDeployService")
public class IntegralDeployServiceImpl implements IntegralDeployService {

	@Autowired
	private IntegralDeployMapper integralDeployMapper;
	
	@Transactional
	@Override
	public Map<String, Object> deleteByintegralautoId(IntegralDeploy integralDeploy) throws Exception {
		// 通过逻辑方式实现删除
		integralDeploy.setStatus("0");
		integralDeploy.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.integralDeployMapper.deleteByintauto(integralDeploy);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> getlistByintegralactivname(String activename) throws Exception {
		// 按照activename查询
		IntegralDeploy integralDeploy = this.integralDeployMapper.getlistByintegralactivname(activename);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), integralDeploy);
	}

	@Override
	public Map<String, Object> getlistIntegral() throws Exception {
		// 查询全部
		List<IntegralDeploy> integralDeploy = this.integralDeployMapper.getlistIntegral();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), integralDeploy);
	}
	
	@Transactional
	@Override
	public Map<String, Object> addIntegral(IntegralDeploy integralDeploy) throws Exception  {
		// 增加配置
		integralDeploy.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		integralDeploy.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		integralDeployMapper.addIntegral(integralDeploy);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}
	
	@Transactional
	@Override
	public Map<String, Object> modifyByintegralautoId(IntegralDeploy integralDeploy) throws Exception {
		// 更新配置
		integralDeploy.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.integralDeployMapper.modifyByintegralautoId(integralDeploy);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
